﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class IntAngleForm : ItemFormTemplate
    {
        public IntAngleForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\IntAngleForm\\IntAngleForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.ReadOnly = false;
            this.demo_control.ValueVisible = true;
            this.demo_control.AllowLoopChanged = false;
            this.demo_control.ReferenceAngleVisible = false;
            this.demo_control.ReferenceAngle = 0;
            this.demo_control.PointerSizePercentage = 15;

            this.readlyOnly_toggleSwitch.IsOn = this.demo_control.ReadOnly;
            this.readlyOnly_toggleSwitch.Toggled += this.ReadlyOnly_toggleSwitch_Toggled;

            this.angleVisible_toggleSwitch.IsOn = this.demo_control.ValueVisible;
            this.angleVisible_toggleSwitch.Toggled += this.ValueVisible_toggleSwitch_Toggled;

            this.allowLoopChanged_toggleSwitch.IsOn = this.demo_control.AllowLoopChanged;
            this.allowLoopChanged_toggleSwitch.Toggled += this.AllowLoopChanged_toggleSwitch_Toggled;

            this.referenceAngleLineVisible_toggleSwitch.IsOn = this.demo_control.ReferenceAngleVisible;
            this.referenceAngleLineVisible_toggleSwitch.Toggled += this.ReferenceAngleVisible_toggleSwitch_Toggled;

            this.referenceAngle_label.Text = this.demo_control.ReferenceAngle.ToString();
            this.referenceAngle_trackBarPlus.Value = this.demo_control.ReferenceAngle;
            this.referenceAngle_trackBarPlus.ValueChanged += this.ReferenceAngle_trackBarPlus_ValueChanged;

            this.pointerSizeMagnification_label.Text = this.demo_control.PointerSizePercentage.ToString();
            this.pointerSizeMagnification_trackBarPlus.Value = this.demo_control.PointerSizePercentage;
            this.pointerSizeMagnification_trackBarPlus.ValueChanged += this.PointerSizePercentage_trackBarPlus_ValueChanged;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void ReadlyOnly_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ReadOnly = control.IsOn;
        }

        private void ValueVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ValueVisible = control.IsOn;
        }

        private void AllowLoopChanged_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.AllowLoopChanged = control.IsOn;
        }

        private void ReferenceAngleVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ReferenceAngleVisible = control.IsOn;
        }

        private void ReferenceAngle_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.ReferenceAngle = (int)control.Value;
            this.referenceAngle_label.Text = this.demo_control.ReferenceAngle.ToString();
        }

        private void PointerSizePercentage_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.PointerSizePercentage = (int)control.Value;
            this.pointerSizeMagnification_label.Text = this.demo_control.PointerSizePercentage.ToString();
        }

        #endregion

    }
}
